package edu.uwm.universitydb.dao.project;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;

import edu.uwm.universitydb.framework.nontransactional.db.command.impl.NonTransactionalDataManipulationCommandBase;
import edu.uwm.universitydb.model.Project;

	public class UpdateProjectCommand  extends NonTransactionalDataManipulationCommandBase
	{

	    /** static string holding insert query */
	    private static final String INSERT_SQL =
	        "update university.project set sponser=?, starting_date=?, ending_date=?, budget=? where pno=?;";

	    /** attribute holding the project information to be inserted */
	    private final Project mProject;

	    /**
	     * @param project
	     */
	    public UpdateProjectCommand(final Project project)
	    {
	        mProject = project;
	    }

	    /*
	     * (non-javadoc)
	     * @see edu.uwm.universitydb.framework.db.command.DBCommand#getSQL()
	     */
	    @Override
	    public String getSQL()
	    {
	        return INSERT_SQL;
	    }

	    /*
	     * (non-javadoc)
	     * @see edu.uwm.universitydb.framework.db.command.DBCommand#setParameters(java.sql.PreparedStatement)
	     */
	    @Override
	    public void setParameters(final PreparedStatement pStmt) throws SQLException
	    {

	        // set sponsor
	        final String sponsor = mProject.getSponsor();
	        pStmt.setString(1, sponsor);
	        // set start date
	        final Date startDate = mProject.getStartDate();
	        final Long startTime = startDate.getTime();
	        final java.sql.Date startDateVal = new java.sql.Date(startTime);
	        pStmt.setDate(2, startDateVal);
	        // set end date
	        final Date endDate = mProject.getEndDate();
	        final Long endTime = endDate.getTime();
	        final java.sql.Date endDateVal = new java.sql.Date(endTime);
	        pStmt.setDate(3, endDateVal);
	        // set budget
	        final Integer budget = mProject.getBudget();
	        pStmt.setInt(4, budget);
	        
	        // set project number
	        final Integer projNum = mProject.getProjectNum();
	        pStmt.setInt(5, projNum);
	    }

}
